package com.qf.osmuser.user.controller;

import com.qf.common.core.annotation.NoLogin;
import com.qf.common.core.common.R;
import com.qf.common.core.dto.BalanceChangeDTO;
import com.qf.osmuser.user.dto.EditUserDTO;
import com.qf.osmuser.user.service.UserService;
import com.qf.osmuser.user.vo.UserInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author TianWenHe
 * @date 2025/6/9
 * @desc
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 获取用户信息
     */
    @GetMapping("/info")
    public R getInfo() {
        UserInfoVO userInfoVO = userService.getInfo();
        return R.ok(userInfoVO);
    }

    /**
     * 获取用户信息
     */
    @GetMapping("/my")
    public R getMyInfo() {
        UserInfoVO userInfoVO = userService.getInfo();
        return R.ok(userInfoVO);
    }

    /**
     * 修改用户信息
     */
    @PostMapping("/update")
    public R update(@RequestBody EditUserDTO editUserDTO){
        userService.update(editUserDTO);
        return R.ok();
    }

    /**
     * 上传用户头像
     */
    @PostMapping("/uploadAvatar")
    public R uploadAvatar(MultipartFile file){
        String filePath = userService.uploadAvatar(file);
        return R.ok(filePath);
    }

    /**
     * 用户签到
     */
    @PostMapping("/sign")
    public R sign(){
        userService.sign();
        return R.ok();
    }

    /**
     * 变更用户余额，正数为充值，负数为退款或消费
     */
    @NoLogin
    @PostMapping("/remote/balance")
    public R changeBalance(@RequestBody BalanceChangeDTO balanceChangeDTO){
        userService.changeBalance(balanceChangeDTO);
        return R.ok();
    }

    /**
     * 获取用户头像集合
     */
    @GetMapping("/avatars")
    public List<String> getAvatarsByUserIds(@RequestParam List<Integer> ids){
        return userService.getAvatarsByUserIds(ids);
    }
}
